package com.ruoyi.user.mapper;

import com.ruoyi.user.domain.UserChatRecord;
import com.ruoyi.user.domain.ChatSession;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 聊天记录Mapper接口
 */
public interface UserChatRecordMapper {
    /**
     * 查询聊天记录
     */
    UserChatRecord selectUserChatRecordById(Long chatId);

    /**
     * 查询聊天记录列表
     */
    List<UserChatRecord> selectUserChatRecordList(UserChatRecord userChatRecord);

    /**
     * 查询会话聊天记录
     */
    List<UserChatRecord> selectUserChatRecordsBySession(@Param("sessionId") Long sessionId, 
                                              @Param("customerId") Long customerId);

    /**
     * 查询用户会话列表
     */
    List<ChatSession> selectUserSessions(Long customerId);

    /**
     * 查询会话信息
     */
    ChatSession selectSessionInfo(@Param("sessionId") Long sessionId, 
                                @Param("customerId") Long customerId);

    /**
     * 新增聊天记录
     */
    int insertUserChatRecord(UserChatRecord userChatRecord);

    /**
     * 修改聊天记录
     */
    int updateUserChatRecord(UserChatRecord userChatRecord);

    /**
     * 删除聊天记录
     */
    int deleteUserChatRecordById(Long chatId);

    /**
     * 批量删除聊天记录
     */
    int deleteUserChatRecordByIds(Long[] chatIds);

    /**
     * 标记消息为已读
     */
    int markMessagesAsRead(@Param("sessionId") Long sessionId, 
                         @Param("customerId") Long customerId, 
                         @Param("chatIds") List<Long> chatIds);

    /**
     * 清空会话聊天记录
     */
    int clearSessionMessages(@Param("sessionId") Long sessionId, 
                           @Param("customerId") Long customerId);

    /**
     * 查询会话未读消息数
     */
    int selectUnreadCountBySession(@Param("sessionId") Long sessionId, 
                                  @Param("customerId") Long customerId);

    /**
     * 查询用户总未读消息数
     */
    int selectTotalUnreadCount(Long customerId);

    /**
     * 查询最后一条消息
     */
    UserChatRecord selectLastMessageBySession(@Param("sessionId") Long sessionId);
}